import * as http from '@api/http'

/**
 * @purpose 获取用户登录凭证
 * @param code
 * @param token
 * @returns {PromiseLike<T> | Promise<T> | *}
 */
export function token (code, token) {
  return http
    .get('sign.token', {
      code: code,
      token: token
    })
    .then(r => r)
}

/**
 * @purpose 通过用户名密码登录
 * @param username
 * @param password
 * @returns {Promise<T>}
 */
export function signInByPassword (username = '', password = '') {
  return http
    .post('sign.signInByPassword', {
      username: username,
      password: password
    })
    .then(r => r.data)
}

/**
 * @purpose 通过授权缓存的用户信息key注册
 * @param bindKey
 * @returns {Promise<T>}
 */
export function signUpByKey (bindKey = '') {
  return http
    .post('sign.signUpByKey', {
      bind_key: bindKey
    })
    .then(r => r)
}

/**
 * @purpose 通过用户名绑定
 * @param username
 * @param password
 * @param bindKey
 * @returns {*|void|AxiosPromise<any>}
 */
export function signUpByUsername (username, password, bindKey) {
  return http
    .post('sign.signUpByUsername', {
      username: username,
      password: password,
      bind_key: bindKey
    }).then(r => r.data)
}

/**
 * @purpose 通过手机号码绑定
 * @param mobile
 * @param code
 * @param bindKey
 * @returns {*|void|AxiosPromise<any>}
 */
export function signUpByMobile (mobile, code, bindKey) {
  return http
    .post('sign.signUpByMobile', {
      mobile: mobile,
      code: code,
      bind_key: bindKey
    }).then(r => r.data)
}

/**
 * @purpose 找回密码
 * @param mobile
 * @param code
 * @param password
 * @returns {*|void|AxiosPromise<any>}
 */
export function findPassword (mobile, code, password) {
  return http
    .post('sign.findPassword', {
      mobile: mobile,
      code: code,
      password: password
    }).then(r => r.data)
}

/**
 * @purpose 获取当前微信端访问的微信用户信息
 * @param code
 * @returns {*|void|AxiosPromise<any>}
 */
export function getNowWeChat (code) {
  return http
    .get('sign.getNowWeChat', {
      code: code
    })
    .then(r => r.data)
}
